package com.mycloud.core.service;

import com.mycloud.core.dao.GenericDao;
import com.mycloud.core.model.IdentifiableEntity;
import org.apache.log4j.Logger;
import org.hibernate.ObjectNotFoundException;
import org.springframework.beans.factory.annotation.Autowired;

import javax.persistence.EntityManagerFactory;

/**
 * User: hossein bahramian
 * Date: Sep 27, 2011
 * Time: 8:33:57 PM
 */
public class GenericServiceImpl<Dao extends GenericDao> implements GenericService {

    protected Dao dao;

    protected Logger logger = Logger.getLogger(getClass());

    @Override
    public void persist(IdentifiableEntity entity) {
        dao.persist(entity);
    }

    @Override
    public <T> T read(Class<T> clazz, Long key) throws ObjectNotFoundException {
        return dao.get(clazz, key);
    }

    @Override
    public <T> T readByName(Class<T> clazz, String name) throws ObjectNotFoundException {
        return dao.readByName(clazz, name);
    }

    @Override
    public <T> Long readIdByName(Class<T> clazz, String name) throws ObjectNotFoundException {
        return dao.readIdByName(clazz, name);
    }

    @Override
    public void delete(Object entity) {
        dao.delete(entity);
    }

}
